package com.book.controller;

import com.book.entity.Admin;
import com.book.entity.Student;
import com.book.service.AdminInfoService;
import com.book.service.StudentInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by 落叶的思恋 on 2017/6/5.
 */

@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
   private AdminInfoService adminInfoService;
    @Autowired
    private StudentInfoService studentInfoService;

    @RequestMapping(value = "/admin",method = RequestMethod.POST)
    @ResponseBody
    public Admin login(@RequestBody Admin admin){

        if (adminInfoService.login(admin.getAdminName(),admin.getAdminPassword())!=null){
           Admin loginAdmin=adminInfoService.login(admin.getAdminName(),admin.getAdminPassword());
            return loginAdmin;
        }else {
            return null;
        }

    }
    @RequestMapping(value = "/student",method = RequestMethod.POST)
    @ResponseBody
    public Student Student(@RequestBody Student student){
        System.out.println();
        if (studentInfoService.login(student.getStudentName(),student.getStudentPassword())!=null){
            Student loginStudent=studentInfoService.login(student.getStudentName(),student.getStudentPassword());
            System.out.println("学生登录结果"+loginStudent);
            return loginStudent;
        }else {
            return null;
        }

    }

}
